import os
import sys

from os.path import join

ROOT = "../evaluation"
LAT_FCTR = float(10000*1000*1000)
OPS_FCTR = float(10000*1000*1000*1000)

def read_file(filename):
    lines = []
    with open(filename, 'r') as f:
        for line in f:
            if line.startswith("Timer 13 MEAN"):
                lines.append(line)

    line = lines[-1]
    time = int(line.split(",")[0].split(":")[1])
    return time


def sosd(d):
    print("SOSD:\n")

    base = read_file(join(ROOT, "sosd_{}_baseline.txt".format(d)))
    llsm = read_file(join(ROOT, "sosd_{}_llsm.txt".format(d)))
    print("{} baseline latency: {:.2f} microseconds".format(d, base/LAT_FCTR))
    print("{} llsm latency: {:.2f} microseconds".format(d, llsm/LAT_FCTR))
    print("")


def main():
    if len(sys.argv) != 2:
        print("Usage: prog expr_num \\in [1-5]")

    dataset = sys.argv[1]

    sosd(dataset)


if __name__ == '__main__':
    main()
